package com.lion.tag.accordion;

import static com.lion.tag.util.AppendUtil.addAttribute;
import static com.lion.tag.util.AppendUtil.appendOptionData;
import static com.lion.tag.util.AppendUtil.isNotBlank;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import com.lion.tag.LionBaseTag;
import com.lion.tag.type.AttributeType;
import com.lion.tag.type.EasyuiOption;
/**
 * 手风琴子菜单
 * 
 *
 * Create on 2016年5月13日 下午3:18:53
 *
 * @author <a href="mailto:125487767@qq.com">liyongyao</a>. 
 *
 */
public class AccordionItem extends LionBaseTag {
	private static final long serialVersionUID = 6490085983437811037L;
	private String title;
	private String icon;
	private String href;
	private String selected;
	private String tools;

	/**
	 * 手风琴子菜单
	 */
	@Override
	public int doStartTag() throws JspException {
		String basePath = getContextPath();
		StringBuilder sb = new StringBuilder(200);
		sb.append("<div ");
		sb = addAttribute(sb, AttributeType.ID.name(), id);
		sb = addAttribute(sb, AttributeType.TITLE.name(), title);
		sb = addAttribute(sb, AttributeType.STYLE.name(), style);
		int hasData = 0;
		hasData = appendOptionData(sb, hasData, EasyuiOption.ICONCLS.name(), icon, true);
		hasData = appendOptionData(sb, hasData, EasyuiOption.SELECTED.name(),selected, false);
		hasData = appendOptionData(sb, hasData, EasyuiOption.TOOLS.name(),tools, false);
		if (isNotBlank(href)) {
			if(!href.startsWith("http")){
				href = basePath + href;
			}
			hasData = appendOptionData(sb, hasData, EasyuiOption.HREF.name(), href, true);
		}
		sb.append(">");
		write(sb);
		return EVAL_BODY_INCLUDE;// 表示标签之间的内容被正常执行
	}

	@Override
	/**  
	 *  doEndTag：当JSP容器遇到自定义标签的结束标志，就会调用doEndTag()方法。doEndTag()方法也返回一个整数值，用来决定程序后续流程。  
	 *  A.Tag.SKIP_PAGE：表示立刻停止执行网页，网页上未处理的静态内容和JSP程序均被忽略任何已有的输出内容立刻返回到客户的浏览器上。  
	 *  B.Tag.EVAL_PAGE：表示按照正常的流程继续执行JSP网页  
	 */
	public int doEndTag() throws JspException {
		try {
			pageContext.getOut().write("</div>");
		} catch (IOException e) {
			throw new JspException(e);
		}
		return EVAL_PAGE;
	}

	/**
	 * @return the style
	 */
	public String getStyle() {
		return style;
	}

	/**
	 * @param style
	 *            the style to set
	 */
	public void setStyle(String style) {
		this.style = style;
	}

	/**
	 * @return the id
	 */
	@Override
	public String getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	@Override
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the icon
	 */
	public String getIcon() {
		return icon;
	}

	/**
	 * @param icon
	 *            the icon to set
	 */
	public void setIcon(String icon) {
		this.icon = icon;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the href
	 */
	public String getHref() {
		return href;
	}

	/**
	 * @param href
	 *            the href to set
	 */
	public void setHref(String href) {
		this.href = href;
	}

	public String getSelected() {
		return selected;
	}

	public void setSelected(String selected) {
		this.selected = selected;
	}

	public String getTools() {
		return tools;
	}

	public void setTools(String tools) {
		this.tools = tools;
	}

}
